// --------------------------------
// <copyright file="TableRowCollection.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Collections;
using System.Data;

namespace Tronsoft.Actucal.Tables
{
    public class TableRowCollection : InternalDataCollectionBase
    {
        private readonly DataRowCollection dataRowCollection;
        private readonly ArrayList rows = new ArrayList();

        internal TableRowCollection(DataRowCollection dataRowCollection)
        {
            if (dataRowCollection == null) throw new ArgumentNullException("dataRowCollection");

            this.dataRowCollection = dataRowCollection;
            foreach (DataRow row in dataRowCollection)
            {
                TableRow tableRow = new TableRow(row);
                rows.Add(tableRow);
            }
        }

        public TableRow this[int rowIndex]
        {
            get { return rows[rowIndex] as TableRow; }
        }

        public object this[int rowIndex, string columnName]
        {
            get { return dataRowCollection[rowIndex][columnName]; }
        }

        public object this[int rowIndex, int columnIndex]
        {
            get { return dataRowCollection[rowIndex][columnIndex]; }
        }

        protected override ArrayList List
        {
            get { return rows; }
        }
    }
}